package com.suypower.carManage.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

public class CardAction extends ActionSupport  implements ServletRequestAware{

	private String id;
	private String card_code;
	private String car_code;
	private String remark;

	public String getCard_code() {
		return card_code;
	}

	public void setCard_code(String cardCode) {
		card_code = cardCode;
	}

	public String getCar_code() {
		return car_code;
	}

	public void setCar_code(String carCode) {
		car_code = carCode;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String execute() {
		String res = "";
		DAO dao = new DAO();
		String sql="";
		if(id==null||id.equals("")){
			sql = "INSERT INTO tb_refuel_card(card_code,car_code,remark)VALUES('"
				+ card_code + "','" + car_code + "','" + remark + "')";
		}else{
			sql="update tb_refuel_card set card_code='"+card_code+"',car_code='"+car_code+"',remark='"+remark+"' where id="+id;
		}
		 
		int count=0;
		try {
			count=dao.execCommand(ConstUtil.DBNAME, sql);
			if(count>0){
				res=this.SUCCESS;
			}else{
				res=this.ERROR;
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
		
		
		return res;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		
	}
}
